###############################
#### Variation across Mesas ###
###############################

rm(list=ls(all=TRUE))

setwd("C:/Users/Lucas/Documents/Ticket Splitting-Voter Transitions/Files for Replication Materials PoBe")

library(eiPack)
library(coda)

data=read.csv(file.path(getwd(),"Data","CABA_data.csv"))


p3007=data$paso_3007
p502o=data$paso_502-data$paso_3007
p501=data$paso_501
p503=data$paso_503
pother=data$paso_8+data$paso_68+data$paso_187+data$paso_234+data$paso_324+data$paso_325+data$paso_505+data$paso_506+data$paso_262+data$paso_504
pno=data$votantes-p3007-p502o-p501-p503-pother

g501=data$gral_501
g502=data$gral_502
g503=data$gral_503
gother=data$gral_187+data$gral_505+data$gral_506
gno=data$votantes-g501-g502-g503-gother

data1=data.frame(p3007,p502o,p501,p503,pother,pno,g501,g502,g503,gother,gno)

bpts=seq.int(0,152,by=8)
bpts=c(bpts,352)


pdf(file.path(getwd(),"Output","variation.pdf"))
layout(matrix(seq(1,12),4,3,byrow=TRUE))
hist(p501,breaks=bpts,xlim=c(0,150),ylim=c(0,0.05),main="Primary: FPV",xlab="")
hist(p3007,breaks=bpts,xlim=c(0,150),ylim=c(0,0.05),main="Primary: UNEN-CS",xlab="")
hist(p502o,breaks=bpts,xlim=c(0,150),ylim=c(0,0.05),main="Primary: UNEN-Others",xlab="")
hist(p503,breaks=bpts,xlim=c(0,150),ylim=c(0,0.05),main="Primary: PRO",xlab="")
hist(pother,breaks=bpts,xlim=c(0,150),ylim=c(0,0.05),main="Primary: Others",xlab="")
hist(pno,breaks=bpts,xlim=c(0,150),ylim=c(0,0.05),main="Primary: No Vote",xlab="")
hist(g501,breaks=bpts,xlim=c(0,150),ylim=c(0,0.05),main="General: FPV",xlab="")
hist(g502,breaks=bpts,xlim=c(0,150),ylim=c(0,0.05),main="General: UNEN",xlab="")
hist(g503,breaks=bpts,xlim=c(0,150),ylim=c(0,0.05),main="General: PRO",xlab="")
hist(gother,breaks=bpts,xlim=c(0,150),ylim=c(0,0.05),main="General: Others",xlab="")
hist(gno,breaks=bpts,xlim=c(0,150),ylim=c(0,0.05),main="General: No Vote",xlab="")
dev.off()

